﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.RequestModels.SysOrder;
using Ekton_Manage_DTO.RequestModels.User;
using Ekton_Manage_Framework.Methods;
using Ekton_Manage_Framework.Redis;
using Ekton_Manage_DTO.RequestModels.Product;
using Ekton_Manage_InfrastructureCore.Common;
using Ekton_Manage_InfrastructureCore.Repositories;
using Ekton_Manage_Mapper.EntityMappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Ekton_Manage_Business
{
    class SelectOrderList
    {
        private readonly Connection _connection;
        private readonly IBaseRepository<order_list, int> _baseMaterialRepository;
        private readonly SerializeParameter _serialize;
        public SelectOrderList(Connection connection, SerializeParameter serialize,IBaseRepository<order_list, int> baseMaterialRepository)
        {
            _connection = connection;
            _serialize = serialize;
            _baseMaterialRepository = baseMaterialRepository;
        }

        /// <summary>
        ///  查询全部订单
        /// </summary>
        /// 
        public async Task<Tuple<List<order_list>, int>> QueryOrderList(QueryDataParame query)
        {
            var orderInfo = await _serialize.ParameConvertToDict(query.parame);
            Expression<Func<order_list, bool>> expression = m => true;
            if (orderInfo.ContainsKey("order_number") && !string.IsNullOrEmpty(orderInfo["order_number"].ToString()))
            {
                expression = expression.ExpressionAnd(m => m.order_number.Contains(orderInfo["order_number"].ToString()));
            }

            if (orderInfo.ContainsKey("commit_tissue") && !string.IsNullOrEmpty(orderInfo["commit_tissue"].ToString()))
            {
                expression = expression.ExpressionAnd(m => m.commit_tissue.Contains(orderInfo["commit_tissue"].ToString()));
            }

            if (orderInfo.ContainsKey("person_name") && !string.IsNullOrEmpty(orderInfo["person_name"].ToString()))
            {
                expression = expression.ExpressionAnd(m => m.person_name.Contains(orderInfo["person_name"].ToString()));
            }

            if (orderInfo.ContainsKey("state") && !string.IsNullOrEmpty(orderInfo["state"].ToString()))
            {
                expression = expression.ExpressionAnd(m => m.state.Contains(orderInfo["state"].ToString()));
            }

            //if (orderInfo.ContainsKey("order_time") && !string.IsNullOrEmpty(orderInfo["order_time"].ToString()))
            //{
            //    expression = expression.ExpressionAnd(m => Convert.ToString(m.order_time).Contains(orderInfo["order_time"].ToString()));
            //}

            if (orderInfo.ContainsKey("user_order_id") && !string.IsNullOrEmpty(orderInfo["user_order_id"].ToString()))
            {
                expression = expression.ExpressionAnd(m => m.user_order_id.Contains(orderInfo["user_order_id"].ToString()));
            }

            if (orderInfo.ContainsKey(" particulars_order_id") && !string.IsNullOrEmpty(orderInfo[" particulars_order_id"].ToString()))
            {
                expression = expression.ExpressionAnd(m => m.user_order_id.Contains(orderInfo[" particulars_order_id"].ToString()));
            }
            var result = await _baseMaterialRepository.QueryPageData(query, expression);
            return result;

        }


        /// <summary>
        /// 添加订单备注
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<Message> InsertUserInfo(DtoSelectOrderListRequests request)
        {
            var userInfo = await _baseMaterialRepository.InsertSingleData(new order_list
            {
               
            });
            return new Message(userInfo.Item1);
        }


    }
}
